package com.lg.delay.queue.controller;

import com.alibaba.fastjson.JSON;
import com.lg.delay.queue.common.domain.LGResult;
import com.lg.delay.queue.pojo.Job;
import com.lg.delay.queue.pojo.JobDie;
import com.lg.delay.queue.service.RedisDelayQueueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author by Mr. Li 2020/12/9 16:18
 */
@Slf4j
@RestController
public class DelayQueueController {

    @Autowired
    private RedisDelayQueueService redisDelayQueueService;

    /**
     * 添加 Job
     *
     * @param job
     * @return
     */
    @PostMapping("/addJob")
    public LGResult addJob(@Validated @RequestBody Job job) {
        log.info("DelayQueueJobController.addJob param is [{}]", JSON.toJSONString(job));
        redisDelayQueueService.addJob(job);
        return LGResult.success();
    }

    @PostMapping("/deleteJob")
    public LGResult deleteJob(@Validated @RequestBody JobDie jobDie) {
        log.info("DelayQueueJobController.deleteJob param is [{}]", JSON.toJSONString(jobDie));
        redisDelayQueueService.deleteJob(jobDie);
        return LGResult.success();
    }

}
